package com.hailiang.study.javase.java.other.staticblock;

import java.lang.reflect.Method;

/**
 * @author hailiang.jiang
 * @date 2021年07月02 16:22
 */
public class StaticClassAndStaticMethod {
    private static final String CLASS_FLAG = "《StaticClassAndStaticMethod》";
    static {
        System.out.println(CLASS_FLAG + "====static block====");
    }

    public static void main(String[] args) throws Exception {
        System.out.println(CLASS_FLAG + "====static method====");

        Class<?> aClass = StaticClassAndStaticMethod.class.getClassLoader().loadClass("com.hailiang.study.javase.java.other.staticblock.ClassDemo");

        System.out.println(CLASS_FLAG + "class name=" + aClass.getName());


        ClassDemo.init();
        //Object o = aClass.getConstructor().newInstance();

        Class<?> paramTypes[] = new Class[1];
        paramTypes[0] = Class.forName("com.hailiang.study.javase.java.other.staticblock.User");
        Method method = aClass.getMethod("add", paramTypes);

        Object paramValues[] = new Object[1];
        paramValues[0] = new User();
        method.invoke(aClass.newInstance(), paramValues);

    }
}
